clear all
set more off, perm
local mydir "`1'"
global Tables	`mydir'/XS/Tables
global Work	`mydir'/XS/DataWork
global Raw	`mydir'/XS/DataRaw
global WRDS	`mydir'/WRDS
/* **************************************************************** */
* #1: Get Compustat data
/* **************************************************************** */
* get data on earnings from compustat.dta (generated by FamaFrench01.do)
use permco permno datadate street if year(datadate)>1962 & datadate<. using $Work/compustat , clear

gen datem=mofd(datadate)
format datem %tm

egen id=group(permco permno)
tsset id datem

tsfill 
replace permco=L.permco if permco==.
replace permno=L.permno if permno==.

by id: ipolate street datem, gen(streetLTM)
keep permco permno datem streetLTM
duplicates tag permco permno datem, gen(dup)
* ****************
* Crosssection/Data/qtly.dta generated by Compustat.do
merge 1:1 permco permno datem using $Work/qtly,keepusing(permco permno datem streetLTM) update replace
drop _merge

egen id=group(permco permno)
tsset id datem
forvalues x=1(1)60 {
	quietly: gen F`x'street=F`x'.streetLTM
}
drop id
save $Work/earnings, replace
* ******************************** 
